#include "threadPool.h"

int recvn(int sockfd,void *buf,int length);

int recvFile(int sockfd){
    char filename[1024]={0};
    int length;

    recvn(sockfd,&length,sizeof(length));
    recvn(sockfd,filename,length);

    off_t filesize;
    recvn(sockfd,&length,sizeof(length));
    recvn(sockfd,&filesize,length);

    int fd=open(filename,O_RDWR|O_CREAT,0666);

    while(1){
        char buf[4096]={0};

        recvn(sockfd,&length,sizeof(length));
        if(length==0){
            break;
        }

        recvn(sockfd,buf,length);
        write(fd,buf,length);
    }

    close(fd);
    return  0;

}


int netDrivePuts(const char *pathname,const char* filename,int netfd){
    recvFile(netfd);
    return 0;
}
